package com.twu.biblioteca;

import java.io.PrintStream;
import java.util.HashMap;
import java.util.Map;

public class LibraryCatalogue {

    private Map<String, Integer> bookList;
    private PrintStream printStream;
    private String thankYouMessage = "Thank You! Enjoy the book.";
    private String sorryMessage = "Sorry we don't have that book yet.";

    public LibraryCatalogue(PrintStream printStream) {
        this.bookList = loadBooks();
        this.printStream = printStream;
    }

    public Map loadBooks() {
        Map<String, Integer> bookList = new HashMap<String, Integer>();
        bookList.put("Book 1", 2);
        bookList.put("Book 2", 0);
        return bookList;
    }

    public void reserveBook(String bookName) {
        if(bookList.containsKey(bookName)){
            if(bookList.get(bookName) > 0){
                printStream.println(thankYouMessage);
                bookList.put(bookName, bookList.get(bookName)-1);
            } else {
                printStream.println(sorryMessage);
            }
        }else {
            printStream.println(sorryMessage);
        }
    }

    public void printBooks() {
        for(String book : bookList.keySet()){
            printStream.println(book);
        }
    }
}
